package com.yhp.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.system.comm.util.Snowflake;
import com.system.common.mapper.BisNurseTypeMapper;
import com.system.common.pojo.BisNurseType;
import com.system.common.pojo.BisNurseTypeExample;
import com.system.common.pojo.BisNurseTypeExample.Criteria;
import com.system.common.pojo.SysUser;

@Service
public class BisNurseTypeServiceImpl implements BisNurseTypeService {

	@Autowired
	private BisNurseTypeMapper bisNurseTypeMapper;
	/**
	 * 综合查询
	 */
	@Override
	public List<BisNurseType> selectByExample(Map<String, Object> map) {
		BisNurseTypeExample example=new BisNurseTypeExample();
			String typeName=(String)map.get("typeName");
			Criteria criteria = example.createCriteria();
			if (StringUtils.isNoneBlank(typeName)) {
				criteria.andTypeNameLike("%"+typeName+"%");
			}
		return bisNurseTypeMapper.selectByExample(example);
	}
	
	@Override
	public List<BisNurseType> selectByExample() {
		BisNurseTypeExample example=new BisNurseTypeExample();
		return bisNurseTypeMapper.selectByExample(example);
	}
	
	/**
	 * 添加
	 */
	@Override
	public int insert(BisNurseType record,HttpSession session) {
		SysUser user=(SysUser)session.getAttribute("user");
		Snowflake sf=new Snowflake(0, 0);
		record.setTypeId(sf.nextId()+"");
		record.setCreateTime(new Date());
		record.setCreateUserId(user.getUserId());
		return bisNurseTypeMapper.insert(record);
	}

	/**
	 * 修改查询
	 */
	@Override
	public BisNurseType selectByPrimaryKey(String typeId) {
		return bisNurseTypeMapper.selectByPrimaryKey(typeId);
	}

	/**
	 * 修改
	 */
	@Override
	public int updateByPrimaryKey(BisNurseType record,HttpSession session) {
		SysUser user=(SysUser)session.getAttribute("user");
		BisNurseType selectByPrimaryKey = bisNurseTypeMapper.selectByPrimaryKey(record.getTypeId());
		record.setCreateTime(selectByPrimaryKey.getCreateTime());
		record.setModifyTime(new Date());
		record.setCreateUserId(selectByPrimaryKey.getCreateUserId());
		record.setModifyUserId(user.getUserId());
		return bisNurseTypeMapper.updateByPrimaryKey(record);
	}

	/**
	 * 删除
	 */
	@Override
	public int deleteByPrimaryKey(String typeId) {
		return bisNurseTypeMapper.deleteByPrimaryKey(typeId);
	}
}
